#!/bin/bash

###############################
## 【健康城市NFS】初始化脚本 ##
###############################

#Jenkian目录
NFS_PATH=/hc/data/nfs/
NFS_JENKINS_PATH=/hc/data/nfs/jenkins

NFS_JENKINS_CFG=("*")

# HCN 存储文件目录
NFS_HCN_REPOSITORY_PATH=/hc/data/nfs/hc-repository
NFS_HCN_REPOSITORY_CFG=("*")

# 参数校验
if [[ ! "$NFS_JENKINS_PATH" ]]; then
	echo "JENKINS存储路径未配置"
	exit 0
fi

if [[ ! "$NFS_HCN_REPOSITORY_PATH" ]]; then
	echo "HCN 存储文件路径未配置"
	exit 0
fi

WORK_PATH=$(pwd)

# Jenkins目录权限设置
mkdir -p $NFS_PATH
# chmod -R 777 $NFS_JENKINS_PATH
# chown -R 1000:1000 $NFS_JENKINS_PATH

# HCN目录权限设置
# mkdir -p $NFS_HCN_REPOSITORY_PATH
# chmod -R 777 $NFS_HCN_REPOSITORY_PATH

sudo yum install -y nfs-utils
sudo systemctl enable nfs-server.service
sudo systemctl restart nfs-server.service

# rm -rf nfs-data/

sudo git clone --depth=1 https://jkcs.bsoft.com.cn/bs-standard-repo-public/ops-public/nfs-springboot-jenkins.git


cd nfs-springboot-jenkins
sudo cat jenkins.tar.gz* | sudo tar -xzf - jenkins

# 拷贝初始文件到Jenkine
#cp nfs-data/jenkins.tar.gz /tmp
#cd /tmp && tar -zvxf jenkins.tar.gz 
sudo rm -rf $NFS_JENKINS_PATH && mv jenkins/ $NFS_PATH
sudo rm -rf /tmp/jenkins.tar.gz


cd $WORK_PATH

# TODO 安装完成校验